package com.xiaobai.frame.config.aspect;

import com.xiaobai.common.utils.result.Result;
import com.xiaobai.frame.config.dict.DictUtils;
import lombok.RequiredArgsConstructor;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 用于拦截方法名带有"query"前缀的方法的查询方法进行字典表字段转换(用于在VO当中)
 */
@Aspect
@Component
@RequiredArgsConstructor
public class DaoDictAspect {
    private static final Logger logger = LoggerFactory.getLogger(DaoDictAspect.class);
    private final DictUtils dictUtils;
    @Pointcut("execution(* com.*.*.controller..query*(..))")
    public void doPointcut() {
    }

    @AfterReturning(pointcut = "doPointcut()", returning = "result")
    public void doAfterReturning(JoinPoint pjp, Result result) {
        try {
            dictUtils.convertDict(result.getData());
        } catch (Exception e) {
            logger.error("字典转换类型异常", e);
        }
    }

}
